/*
 *  Copyright (c) 2010-2023
 */
package net.siufung.market.base.uuid.controller.regulation;

import java.util.Objects;
import net.siufung.core.exception.BizServiceException;
import net.siufung.core.model.VerifyRepeatDto;
import net.siufung.core.model.enums.MethodEventEnum;
import net.siufung.core.model.regulation.AbstractRegulation;
import net.siufung.market.base.uuid.mapper.ISysUuidRulesMapper;
import net.siufung.market.base.uuid.mapper.entity.SysUuidRules;
import net.siufung.market.base.uuid.controller.model.SysUuidRulesModel;
import lombok.extern.slf4j.Slf4j;
import lombok.AllArgsConstructor;

/**
 * 流水号配置表 逻辑规则校验
 *
 * @author 陈建峰
 * @since 2023-10-09 22:16:17
 */
public class SysUuidRulesRegulation {

    @Slf4j
    @AllArgsConstructor
    public static class Save extends AbstractRegulation<SysUuidRulesModel.SaveDto> {

        private static final long serialVersionUID = 1L;

        private final ISysUuidRulesMapper sysUuidRulesMapper;

        @Override
        public boolean isSatisfiedBy(SysUuidRulesModel.SaveDto sysUuidRulesModelSaveDto) {
            VerifyRepeatDto<?> verifyRepeatDto = new VerifyRepeatDto<>();
            verifyRepeatDto.setMethodEventEnum(MethodEventEnum.ADD);
            verifyRepeatDto.setPk(null);
            return Boolean.TRUE;
        }
    }


    @Slf4j
    @AllArgsConstructor
    public static class Update extends AbstractRegulation<SysUuidRulesModel.UpdateDto> {

        private static final long serialVersionUID = 1L;

        private final ISysUuidRulesMapper sysUuidRulesMapper;

        @Override
        public boolean isSatisfiedBy(SysUuidRulesModel.UpdateDto sysUuidRulesModelUpdateDto) {
            VerifyRepeatDto<Integer> verifyRepeatDto = new VerifyRepeatDto<>();
            verifyRepeatDto.setMethodEventEnum(MethodEventEnum.UPDATE);
            verifyRepeatDto.setPk(sysUuidRulesModelUpdateDto.getId());
            return Boolean.TRUE;
        }
    }

    @Slf4j
    @AllArgsConstructor
    public static class Remove extends AbstractRegulation<Integer> {

        private static final long serialVersionUID = 1L;

        private final ISysUuidRulesMapper sysUuidRulesMapper;

        @Override
        public boolean isSatisfiedBy(Integer id) {
            if(Objects.isNull(id)){
                throw new BizServiceException("无效主键！");
            }
            SysUuidRules sysUuidRules = sysUuidRulesMapper.selectById(id);
            if(Objects.isNull(sysUuidRules)){
                throw new BizServiceException("流水号配置表不存在！");
            }
            return Boolean.TRUE;
        }
    }

    @Slf4j
    @AllArgsConstructor
    public static class Status extends AbstractRegulation<Integer> {

        private static final long serialVersionUID = 1L;

        private final ISysUuidRulesMapper sysUuidRulesMapper;

        @Override
        public boolean isSatisfiedBy(Integer id) {
            if(Objects.isNull(id)){
                throw new BizServiceException("无效主键！");
            }
            SysUuidRules sysUuidRules = sysUuidRulesMapper.selectById(id);
            if(Objects.isNull(sysUuidRules)){
                throw new BizServiceException("流水号配置表不存在！");
            }
            return Boolean.TRUE;
        }
    }






}